//
//  TSTabbarController.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/10/21.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSTabbarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabbar = UITabBar.appearance()
        tabbar.tintColor = UIColor(red: 245/255.0, green: 98/255.0, blue: 93/255.0, alpha: 1)
        
        addChildViewControllers()
        
        let tsTabbar = TSTabbar()
        tsTabbar.ts_delegate = self;
        self.setValue(tsTabbar, forKey: "tabBar")
    }
    

    private func addChildViewControllers() {
        setChildViewController(TSMainViewController(), title: "首页", imageName: "tabbar_home")
        setChildViewController(TSServiceViewController(), title: "客服", imageName: "tabbar_service")
        setChildViewController(TSInviteViewController(), title: "邀请好友", imageName: "tabbar_invite")
        setChildViewController(TSAccountViewController(), title: "我的", imageName: "tabbar_mine")
        
        setChildViewController(TSAddVipViewController(), title: "增加好友", imageName: "tabbar_mine")
    }

    /// 初始化子控制器
    private func setChildViewController(_ childController: UIViewController, title: String, imageName: String) {
            
//        childController.tabBarItem.title = title
        childController.tabBarItem.image = UIImage(named: imageName)!.withRenderingMode(.alwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")!.withRenderingMode(.alwaysOriginal)
        addChild(TSBaseNavigationController(rootViewController: childController))
        }

}

extension TSTabbarController : TSTabbarDelegate {
    
    func didClickvip() {
        
        let array = self.children
        array.first?.tabBarController?.selectedIndex = 4
//        let currentVc = UIViewController.currentViewController()
//        currentVc.present(TSAddVipViewController(), animated: true, completion: nil)
    }
}
